home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / ColorSync 2.5.1 SDK / Sample Code / CSDemo 2.5 / CSDemoSources / winProfID.c < prev    next >
Encoding:
Text File  |  1998-09-09  |  29.2 KB  |  1,004 lines  |  [TEXT/CWIE]

  1. // A profID window
  2. //
  3. // David Hayward 
  4. // Developer Technical Support
  5. // AppleLink: DEVSUPPORT
  6. //
  7. // Copyrite 1995, Apple Computer,Inc
  8. //
  9. // This file contains the menus routines for a profile window.
  10. // 
  11. // 12/13/94    david    first cut
  12.  
  13.  
  14. #include <QuickDraw.h>
  15. #include <Icons.h>
  16. #include <Fonts.h>
  17. #include <LowMem.h>
  18. #include <Files.h>
  19. #include <TextUtils.h>
  20. #include <QDOffScreen.h>
  21. #include <Resources.h>
  22. #include <StandardFile.h>
  23.  
  24. #include "appGlobals.h"
  25. #include "appMain.h"
  26. #include "appMenus.h"
  27. #include "appErrors.h"
  28. #include "appAEvts.h"
  29.  
  30. #include "win.h"
  31. #include "winTables.h"
  32. #include "winProfID.h"
  33. #include "winProfIDGetSet.h"
  34. #include "winProfList.h"
  35. #include "winProfListGetSet.h"
  36.  
  37. #include "stringUtils.h"
  38. #include "colorsyncUtils.h"
  39. #include "resourceUtils.h"
  40.  
  41.  
  42. /**\
  43. |**| ==============================================================================
  44. |**| PRIVATE TYPEDEFS
  45. |**| ==============================================================================
  46. \**/
  47. typedef struct FlagList
  48. {
  49.     short    count ;            // 1-based count of structs to follow 
  50.     struct
  51.     {
  52.         short    shift ;            // bits to shift over
  53.         short    mask ;            // bits to then mask over
  54.         short    value ;            // resulting value
  55.         Str27    string ;
  56.     } entry[];
  57. } FlagList, *FlagListPtr, **FlagListHdl ;
  58.  
  59.  
  60. /**\
  61. |**| ==============================================================================
  62. |**| PRIVATE DEFINES
  63. |**| ==============================================================================
  64. \**/
  65. #define rProfileWindID                1000            // 'WIND' resource id
  66. #define rProfileLabelsStringID        1000            // 'STR ' resource id
  67. #define rProfileVarsStringID        1001            // 'STR ' resource id
  68. #define rProfileWhereVarStringID    1002            // 'STR ' resource id
  69. #define rProfIDIconID                5003            // icon family resource id
  70.  
  71.  
  72. /**\
  73. |**| ==============================================================================
  74. |**| PRIVATE FUNCTION PROTOTYPES
  75. |**| ==============================================================================
  76. \**/
  77. void        DoDrawProfData            ( winHandle win ) ;
  78. void        MungeProfileHeader2        ( CMAppleProfileHeader head, Handle text ) ;
  79. OSErr        RendIntent2String        ( unsigned long intent, StringPtr dest ) ;
  80. OSErr        ColorSpace2String        ( OSType spaceType, StringPtr dest ) ;
  81. OSErr        ProfileClass2String        ( OSType classType, StringPtr dest ) ;
  82. OSErr        DoCreateProfWindow        ( winHandle win ) ;
  83. void        ProfIDSearchListCmnd    ( winHandle win ) ;
  84. void        SaveCmndProfID            ( winHandle win ) ;
  85. void        SaveAsCmndProfID        ( winHandle win ) ;
  86. void        RevertCmndProfID        ( winHandle win ) ;
  87. long        PopUpMenuSelectFont        ( MenuHandle theMenu, short top, short left,
  88.                                           short popUpItem, short font, short size) ;
  89. OSErr        GetFlagListStringPtr    ( short id, unsigned long flags, StringPtr dest ) ;
  90. OSErr        BuildFlagListMenu        ( short id, unsigned long flags, MenuHandle menu ) ;
  91. OSErr        SetFlagFromMenuItem        ( short id, unsigned long *flags, short mitem ) ;
  92.  
  93.  
  94. /**\
  95. |**| ==============================================================================
  96. |**| PUBLIC FUNCTIONS
  97. |**| ==============================================================================
  98. \**/
  99.  
  100.  
  101. /*------------------------------------------------------------------------------*\
  102.     winUpdateProfID
  103.  *------------------------------------------------------------------------------*
  104.         This is a UpdateProcPtr for ProfID windows.  
  105.         It handles all drawing into the window.
  106.         For ProfList windows, this means that this routine is responible for
  107.         drawing the the basic profID info into the window.
  108.         This ProcPtr is envoked by CallWinUpdateProc() which is called by:
  109.             DoUpdateEvent() which dispaches update events.
  110. \*------------------------------------------------------------------------------*/
  111. void    winUpdateProfID ( winHandle win, EventRecord *e )
  112. {
  113.     WindowRef        window = (WindowRef)e->message;
  114.     GrafPtr            savedPort ;
  115.     
  116.     GetPort(&savedPort ) ;    
  117.     SetPort( (GrafPtr)window ) ;
  118.  
  119.     BeginUpdate( window ) ;
  120.  
  121.     DoDrawProfData( win ) ;
  122.     
  123.     // signal that we finished drawing
  124.     EndUpdate( window ) ;
  125.     SetPort( savedPort ) ;
  126. }
  127.  
  128.  
  129. /*------------------------------------------------------------------------------*\
  130.     winClickProfID
  131.  *------------------------------------------------------------------------------*
  132.         This is a ClickProcPtr for ProfID windows.
  133.         So far, all this contains is a crude handling of the popup menus
  134.         Other things, such as initiating a drag-and-drop should also go here
  135.         This ProcPtr is envoked by CallWinClickProc() which is called by:
  136.             DoMouseDownEvent() which dispaches mouse down events 
  137. \*------------------------------------------------------------------------------*/
  138. void winClickProfID ( winHandle win, EventRecord *e ) 
  139. {
  140.     CMError                    cmerr ;
  141.     CMProfileIdentifierHdl    id;
  142.     CMAppleProfileHeader    head ;
  143.     unsigned long            vers ;
  144.     unsigned long            *flagPtr ;
  145.     Point                    where ;
  146.     Rect                    varsRect ;
  147.     
  148.     varsRect = GetRect ( rProfileVarsStringID ) ;
  149.  
  150.     // if in correct region
  151.     where = e->where;
  152.     GlobalToLocal(&where);
  153.     
  154.     if ( (where.h >= varsRect.left) && (where.h <= varsRect.left+8) )
  155.     {
  156.         short        row, resID, mitem;
  157.         long        mresult;
  158.         MenuHandle    menu;
  159.         Point        mOrigin ;
  160.         
  161.         row = (where.v - varsRect.top) /12;
  162.         
  163.         if ( row>=14 && row<=17 )
  164.         {
  165.             id = GetProfIDIDHdl( win ) ;
  166.             head.cm2 = ((**id).profileHeader) ;
  167.         
  168.             vers = head.cm2.profileVersion ;
  169.     
  170.             menu = NewMenu(5000,"\ppopup");
  171.             InsertMenu(menu,-1);
  172.             
  173.             mOrigin.h = varsRect.left;
  174.             mOrigin.v = varsRect.top + 12*row;            
  175.             LocalToGlobal(&mOrigin);
  176.  
  177.             flagPtr = nil;
  178.             
  179.             if (row==15 && vers>=cmCS2ProfileVersion)        // CS2 Atrb1
  180.             {    flagPtr = &(head.cm2.deviceAttributes[1]) ;
  181.                 resID = 1001;
  182.             }                
  183.             if (row==16 && vers>=cmCS2ProfileVersion)        // CS2 Flags
  184.             {    flagPtr = &(head.cm2.flags) ;
  185.                 resID = 1002;
  186.             }                
  187.             if (row==16 && vers<cmCS2ProfileVersion)        // CS1 Flags
  188.             {    flagPtr = (unsigned long *)&(head.cm1.flags) ;
  189.                 resID = 1003;
  190.             }                
  191.             if (row==17)                                    // CS Intent
  192.             {    flagPtr = &(head.cm2.renderingIntent) ;
  193.                 resID = 1000;
  194.             }                
  195.  
  196.             if (flagPtr) cmerr = BuildFlagListMenu( resID, *flagPtr, menu ) ;
  197.             
  198.             if (flagPtr && !cmerr)
  199.             {
  200.                 mresult = PopUpMenuSelectFont(menu,mOrigin.v,mOrigin.h,0, 3, 9);
  201.                 DeleteMenu((**menu).menuID);
  202.                 mitem = LoWord(mresult);
  203.  
  204.                 cmerr = SetFlagFromMenuItem( resID, flagPtr, mitem ) ;
  205.                 
  206.                 if (!cmerr)
  207.                 {
  208.                     SetWinDirty( win, true ) ;
  209.                     InvalRect( &varsRect ) ;
  210.                     DoAppAdjustMenus() ;        // undim app items
  211.                 }
  212.             }
  213.             DisposeMenu(menu);
  214.         }
  215.     }
  216. }
  217.  
  218.  
  219. /*------------------------------------------------------------------------------*\
  220.     winCloseProfID
  221.  *------------------------------------------------------------------------------*
  222.         This is a CloseProcPtr for ProfID windows.
  223.         So far, all this does is call DisposeWinHandle()
  224.         This win type doesn't need to be saved so there is no reason to prompt the
  225.         user to save the file here.
  226.         This ProcPtr is envoked by CallWinCloseProc() which is called by:
  227.             DoMouseDownEvent() which dispached click events (e.g. close box), and
  228.             MenuProcPtrs which are called whenever menu events occur.
  229. \*------------------------------------------------------------------------------*/
  230. void    winCloseProfID ( winHandle win ) 
  231. {
  232.     DisposeWinHandle( win ) ;
  233. }
  234.  
  235.  
  236. /*------------------------------------------------------------------------------*\
  237.     winMenuProfID
  238.  *------------------------------------------------------------------------------*
  239.         This is a MenuProcPtr for ProfID windows.
  240.         This routine dispatches any menu commands that the window can handle
  241.         to the appropriate function.
  242.         This ProcPtr is envoked by CallWinMenuProc() which is called by:
  243.             HandleMenuCommand() which dispatches all menu events.
  244. \*------------------------------------------------------------------------------*/
  245. void winMenuProfID ( winHandle win, long menuResult, Boolean *didit )
  246. {
  247.     short            menuID;
  248.     short            menuItem;
  249.     
  250.     *didit = true ;
  251.     menuID   = HiWrd(menuResult) ;
  252.     menuItem = LoWrd(menuResult) ;
  253.     switch ( menuID )
  254.     {
  255.         case mFile:
  256.             switch ( menuItem )
  257.             {
  258.                 case iSave:                // save this document under the name it was opened
  259.                     SaveCmndProfID( win ) ;
  260.                     break ;
  261.                 case iSaveAs:            // save this document under a new name
  262.                     SaveAsCmndProfID( win ) ;
  263.                     break ;
  264.                 case iRevert:            // discard all changes made to the document since it was last saved
  265.                     RevertCmndProfID( win ) ;
  266.                     break ;
  267.                 default :
  268.                     *didit = false ;
  269.                     break ;
  270.             }
  271.             break ;
  272.  
  273.         case mProfileLists:
  274.             switch ( menuItem )
  275.             {
  276.                 case iCSFolderUqid:
  277.                     ProfIDSearchListCmnd( win ) ;
  278.                     break ;
  279.                 default :
  280.                     *didit = false ;
  281.                     break ;
  282.             }
  283.             break ;
  284.  
  285.         default :
  286.             *didit = false ;
  287.             break ;
  288.     }
  289.     HiliteMenu(0) ;        // Unhighlight whatever MenuSelect or MenuKey hilited
  290. }
  291.  
  292.     
  293. /*------------------------------------------------------------------------------*\
  294.     winUpdateMenusProfID
  295.  *------------------------------------------------------------------------------*
  296.         This is a UpdateMenuProcPtr for ProfID windows.
  297.         This routine enables any menu commands that the window can handle.
  298.         This ProcPtr is envoked by CallWinUpdateMenusProc() which is called by:
  299.             DoAppAdjustMenus() which dispatches all menu events.
  300. \*------------------------------------------------------------------------------*/
  301. void winUpdateMenusProfID ( winHandle win ) 
  302. {
  303.     MenuHandle        theMenu ;
  304.     FSSpec            spec ;
  305.     Boolean            dirty ;
  306.     Boolean            hasFile ;
  307.     OSType            subtype ;
  308.     winHandle        frontWin;
  309.     
  310.     frontWin = GetFrontWindowWinHandle() ;
  311.     
  312.     if ( win == frontWin )
  313.     {
  314.         spec = GetWinFSSpec( win ) ;
  315.         dirty = GetWinDirty( win ) ;
  316.         hasFile = ( spec.name[0] > 0 ) ;
  317.         subtype = GetWinSubtype( win ) ;
  318.  
  319.         // do the file menu
  320.         theMenu = GetMenuHandle ( mFile ) ;
  321.     
  322.             EnableItem ( theMenu, kWholeMenu ) ;
  323.             EnableItem ( theMenu, iClose ) ;
  324.             EnableItem ( theMenu, iSaveAs ) ;
  325.         
  326.             // for the next 2, check to see if the document has been changed
  327.             if ( dirty && subtype==kFileSubType)
  328.                 EnableItem ( theMenu, iSave ) ;
  329.             if ( dirty && subtype==kFileSubType && hasFile )
  330.                 EnableItem ( theMenu, iRevert ) ;
  331.  
  332.         // do the profiles list submenu
  333.         theMenu = GetMenuHandle ( mProfileLists ) ;
  334.         
  335.             EnableItem ( theMenu, kWholeMenu ) ;
  336.             EnableItem ( theMenu, iCSFolderUqid ) ;
  337.     }
  338. }
  339.  
  340.  
  341. /*------------------------------------------------------------------------------*\
  342.     winAllocProfID
  343.  *------------------------------------------------------------------------------*
  344.         This is a AllocProcPtr for ProfID windows.
  345.         This routine is responsible for filling in all the needed fields of the
  346.         winHandle structure.  This routine shouldn't be called directly.
  347.         Instead, the code which needs to create a document of this type should
  348.         call NewWinHandle(win,winAllocProfID) to envoke this function.
  349.         This ProcPtr is envoked by NewWinHandle() which is called by:
  350.             app_aeODOC_handler() which handles ODOC AppleEvents, and
  351.             app_aePDOC_handler() which handles PDOC AppleEvents.
  352. \*------------------------------------------------------------------------------*/
  353. OSErr winAllocProfID ( winHandle win )
  354. {
  355.     OSErr            err = noErr ;
  356.     ProfIDDataHdl    data ;
  357.         
  358.     // we need ColorSync 2.
  359.     if (!CS2_available())
  360.         return eWarnCantOpenFileNoColorSync2 ;
  361.  
  362.     // set the window type
  363.     SetWinType( win, kProfIDType ) ;
  364.     
  365.     // stuff winHandle fields
  366.     SetWinUpdateProc        ( win,      (UpdateProcPtr) winUpdateProfID ) ;
  367.     SetWinClickProc            ( win,       (ClickProcPtr) winClickProfID ) ;
  368.     SetWinMenuProc            ( win,        (MenuProcPtr) winMenuProfID ) ;
  369.     SetWinUpdateMenusProc    ( win, (UpdateMenusProcPtr) winUpdateMenusProfID ) ;
  370.     SetWinOpenProc            ( win,        (OpenProcPtr) winOpenProfID ) ;
  371.     SetWinCloseProc            ( win,       (CloseProcPtr) winCloseProfID ) ;
  372.     SetWinDisposeProc        ( win,     (DisposeProcPtr) winDisposeProfID ) ;
  373.  
  374.     // allocate data handle
  375.     data = (ProfIDDataHdl)NewHandleClear( sizeof(ProfIDDataRec) ) ;    
  376.     if( data == nil ) return MemError() ;
  377.     SetWinData( win, (Handle)data ) ;
  378.     
  379.     return err ;    
  380. }
  381.  
  382.  
  383. /*------------------------------------------------------------------------------*\
  384.     winOpenProfID
  385.  *------------------------------------------------------------------------------*
  386.         This is a OpenProcPtr for ProfID windows.
  387.         This routine is responsible for opening a ProfID window after all the
  388.         needed fields of the winHandle structure have been filled in by winAllocProfID.
  389.         On entry the DocumentRecord must contain a valid FSSpec.
  390.         If a ProfID window for the FSSpec is already onen, then this routine 
  391.         will bring it to the front instead of opening a second window.
  392.         This routine shouldn't be called directly.  Instead, the code which needs
  393.         to create a document of this type should call NewWinHandle(win,winAllocProfID),
  394.         SetWinFSSpec (win,spec), and then CallWinOpenProc(win) to envoke this function.
  395.         This ProcPtr is envoked by CallWinOpenProc() which is called by:
  396.             app_aeODOC_handler() which handles ODOC AppleEvents, and
  397.             app_aePDOC_handler() which handles PDOC AppleEvents.
  398. \*------------------------------------------------------------------------------*/
  399. OSErr winOpenProfID ( winHandle win )
  400. {
  401.     OSErr                err = noErr ;
  402.     winHandle            existingWin ;
  403.     FSSpec                spec ;
  404.     CMProfileIdentifierHdl id ;
  405.     OSType                subtype ;    // this is the subtype of window ('file' 'embd' or 'sysp')
  406.     unsigned long        index ;        // if embeded subtype then this tells us which one
  407.     Boolean                alreadyOpen = false;
  408.     short                count, i ;
  409.     
  410.     spec = GetWinFSSpec( win ) ;
  411.     subtype = GetWinSubtype( win ) ;
  412.     index = GetProfIDIndex( win ) ;
  413.  
  414.     // see if already open
  415.     switch (subtype)
  416.     {
  417.         case kHandleSubType :
  418.              break ;
  419.              
  420.         case kFileSubType :
  421.              if ( FindWinHandle( &spec, kProfIDType, subtype, 1, 1, &existingWin ) == 1 )
  422.                  alreadyOpen = true ;
  423.              break ;
  424.              
  425.         case kEmbededSubType :
  426.             count = FindWinHandle( &spec, kProfIDType, subtype, 0, 0, nil ) ;
  427.             for (i=1; i<=count && !alreadyOpen; i++)
  428.             {
  429.                 if ( FindWinHandle( &spec, kProfIDType, subtype, i, 1, &existingWin ) == 1 )
  430.                     if ( GetProfIDIndex(existingWin) == index )
  431.                         alreadyOpen = true ;
  432.             }
  433.              break ;
  434.     }
  435.      
  436.      if (alreadyOpen)
  437.     {
  438.         // bring it to the front
  439.         SelectWindow( GetWinWindow(existingWin) ) ;        
  440.         return kWasAlreadyOpen ;
  441.     }
  442.  
  443.     switch (subtype)
  444.     {
  445.         case kHandleSubType :
  446.              break ;
  447.  
  448.         case kFileSubType :
  449.             err = ReadProfileIdentifier( spec, &id ) ;
  450.             if ( err ) return err;
  451.             SetProfIDIDHdl( win, id ) ;            // set the window's data's profile ref
  452.             break ;
  453.             
  454.         case kEmbededSubType :
  455.             //? the prof is valid
  456.             //? the spec is the spec of the pict file
  457.             break ;
  458.     }
  459.     
  460.     err = DoCreateProfWindow( win ) ;
  461.     return err ;    
  462. }
  463.  
  464.  
  465. /*------------------------------------------------------------------------------*\
  466.     winDisposeProfID
  467.  *------------------------------------------------------------------------------*
  468.         This is a DisposeProcPtr for ProfID windows.
  469.         This routine is responsible for disposing of any data that was allocated
  470.         by the document and stored in the its data handle.
  471.         This ProcPtr is envoked by CallWinDisposeProc() which is called by:
  472.             DisposeWinHandle() which disposes of the entire winHandle.
  473. \*------------------------------------------------------------------------------*/
  474. void winDisposeProfID ( winHandle win )
  475. {
  476.     ProfIDDataHdl    data ;
  477.     CMProfileIdentifierHdl id ;
  478.  
  479.     data = (ProfIDDataHdl) GetWinData ( win ) ;
  480.     if ( data==nil ) return;
  481.  
  482.     id = GetProfIDIDHdl( win ) ;
  483.     if ( id != nil )
  484.         DisposeHandle( (Handle)id ) ;
  485.  
  486.     // lastly, dispose of the data handle
  487.     DisposeHandle( (Handle)data ) ;
  488. }
  489.  
  490.  
  491. /**\
  492. |**| ==============================================================================
  493. |**| PRIVATE FUNCTIONS
  494. |**| ==============================================================================
  495. \**/
  496.  
  497.  
  498. static void DoDrawProfData ( winHandle win ) 
  499. {    
  500.     long                length ;
  501.     Rect                labelRect, varsRect, whereRect, iconRect ; // = {7,53,39,85} ;
  502.     Handle                labelText, varText,  whereText ;
  503.     CMProfileIdentifierHdl id;
  504.     CMAppleProfileHeader    head ;
  505.     CMError                cmerr ;
  506.     OSType                subtype ;
  507.     unsigned long        vers ;
  508.     Str255                name, path ;
  509.     FSSpec                spec ;
  510.  
  511. // get rects from resources
  512.     labelRect = GetRect ( rProfileLabelsStringID ) ;
  513.     varsRect = GetRect ( rProfileVarsStringID ) ;
  514.     whereRect = GetRect ( rProfileWhereVarStringID ) ;
  515.     iconRect = GetRect ( rProfIDIconID ) ;
  516.  
  517. // draw icon
  518.     PlotIconID( &iconRect, atNone, ttNone, rProfIDIconID ) ;
  519.  
  520. // draw labels
  521.     TextSize(9) ;
  522.     TextFace(bold) ;
  523.     TextFont(applFont) ;
  524.  
  525.     labelText = GetResource( 'TEXT', rProfileLabelsStringID ) ;
  526.     
  527.     HLock( labelText ) ;
  528.     length = GetHandleSize( labelText ) ;
  529.     TETextBox( *labelText, length, &labelRect, teFlushRight) ;
  530.     HUnlock( labelText ) ;
  531.     ReleaseResource( labelText ) ;
  532.  
  533.     TextSize(9) ;
  534.     TextFace(0) ;
  535.     TextFont(applFont) ;
  536.  
  537. // get the ProfID's vital stats
  538.     subtype = GetWinSubtype( win ) ;
  539.     spec = GetWinFSSpec( win ) ;
  540.     id = GetProfIDIDHdl( win ) ;
  541.     HLock ( (Handle)id ) ;
  542.     head.cm2 = ((**id).profileHeader) ;
  543.     (void) GetProfileIdentifierSize( *id, &(head.cm2.size) ) ;
  544.  
  545. // get the ProfID's name element
  546.     cmerr = GetProfileIdentName( *id, (StringPtr)&name ) ;
  547.     HUnlock ( (Handle)id ) ;
  548.     if (cmerr) return ;
  549.  
  550. // draw the ProfID's name
  551.     MoveTo (varsRect.left,varsRect.top-19) ;
  552.     TextFace(italic) ;
  553.     DrawString( name ) ;
  554.     TextFace(0) ;
  555.  
  556. // get ProfID version
  557.     vers = head.cm2.profileVersion ;
  558.  
  559. // set up the ProfID info text
  560.     varText = GetResource( 'TEXT', rProfileVarsStringID ) ;
  561.     if (vers >= cmCS2ProfileVersion)
  562.         MungeProfileHeader2( head, varText ) ;
  563.     else return ;                            // need a better error code here
  564.  
  565. // set up the "where" info text
  566.     whereText = GetResource( 'TEXT', rProfileWhereVarStringID ) ;
  567.     FSSpecToString( GetWinFSSpec(win), path, (subtype==kEmbededSubType) ) ;
  568.     MyReplaceText ( whereText, path, "\p«Where»" ) ;
  569.     MyReplaceText ( whereText, "\p:\0", "\p:" ) ;
  570.  
  571. // draw the profile info
  572.     HLock( varText ) ;
  573.     length = GetHandleSize( varText ) ;
  574.     TETextBox( *varText, length, &varsRect, teFlushLeft) ;
  575.     HUnlock( varText ) ;
  576.     ReleaseResource( varText ) ;    
  577.  
  578. // draw the "where" information
  579.     HLock( whereText ) ;
  580.     length = GetHandleSize( whereText ) ;
  581.     TETextBox( *whereText, length, &whereRect, teFlushLeft) ;
  582.     HUnlock( whereText ) ;
  583.     ReleaseResource( whereText ) ;
  584. }
  585.  
  586.  
  587. /*------------------------------------------------------------------------------*\
  588. \*------------------------------------------------------------------------------*/
  589. static void MungeProfileHeader2 ( CMAppleProfileHeader head, Handle text )
  590. {
  591.     CM2Header                cm2 ;
  592.     Str255                    myStr ;
  593.     unsigned long            rawSecs ;
  594.  
  595. // get the profile's header
  596.     cm2 = head.cm2 ;
  597.     
  598. // Vers
  599.     VersionToString( cm2.profileVersion, myStr) ;
  600.     MyReplaceText( text, myStr, "\p«Vers»" ) ;
  601. // Embed
  602. // Size
  603.     FormatLong( cm2.size, rBytesFMAT, myStr) ;
  604.     MyReplaceText( text, myStr, "\p«Size»" ) ;
  605. // ColorSpace
  606.     ColorSpace2String ( cm2.dataColorSpace, myStr ) ;
  607.     MyReplaceText( text, myStr, "\p«ColorSpace»" ) ;
  608. // InterchangeSpace
  609.     ColorSpace2String ( cm2.profileConnectionSpace, myStr ) ;
  610.     MyReplaceText( text, myStr, "\p«XchngSpace»" ) ;
  611. // CMM
  612.     OSTypeToString( cm2.CMMType, myStr) ;
  613.     MyReplaceText( text, myStr, "\p«CMM»" ) ;
  614. // Class
  615.     OSTypeToString( cm2.profileClass, myStr) ;
  616.     ProfileClass2String ( cm2.profileClass, myStr ) ;
  617.     MyReplaceText( text, myStr, "\p«Class»" ) ;
  618. // Manufacturer
  619.     OSTypeToString( cm2.deviceManufacturer, myStr) ;
  620.     MyReplaceText( text, myStr, "\p«Manufacturer»" ) ;
  621. // DeviceModel
  622.     LongHexToString ( cm2.deviceModel, myStr) ;
  623.     MyReplaceText( text, myStr, "\p«DeviceModel»" ) ;
  624. // Attributes
  625.     LongHexToString ( cm2.deviceAttributes[0], myStr) ;
  626.     MyReplaceText( text, myStr, "\p«Attributes0»" ) ;
  627.     LongHexToString ( cm2.deviceAttributes[1], myStr) ;
  628.     MyReplaceText( text, myStr, "\p«Attributes1»" ) ;
  629. // Flags
  630.     LongHexToString ( cm2.flags, myStr) ;
  631.     MyReplaceText( text, myStr, "\p«Flags»" ) ;
  632. // Intent
  633.     RendIntent2String ( cm2.renderingIntent, myStr ) ;
  634.     MyReplaceText( text, myStr, "\p«Intent»" ) ;
  635. // White
  636.     MyReplaceText( text, "\p«X», «Y», «Z»", "\p«White»" ) ;
  637.     FormatFixed( cm2.white.X, rDotThreeFMAT, myStr) ;
  638.     MyReplaceText( text, myStr, "\p«X»" ) ;
  639.     FormatFixed( cm2.white.Y, rDotThreeFMAT, myStr) ;
  640.     MyReplaceText( text, myStr, "\p«Y»" ) ;
  641.     FormatFixed( cm2.white.Z, rDotThreeFMAT, myStr) ;
  642.     MyReplaceText( text, myStr, "\p«Z»" ) ;
  643. // Created
  644.     MyReplaceText( text, "\p«Date», «Time»", "\p«Created»" ) ;
  645.     DateToSeconds( (DateTimeRec*)&(cm2.dateTime), &rawSecs) ;
  646.     IUDateString( rawSecs, abbrevDate, myStr) ;
  647.     MyReplaceText( text, myStr, "\p«Date»" ) ;
  648.     IUTimeString( rawSecs, false, myStr) ;
  649.     MyReplaceText( text, myStr, "\p«Time»" ) ;
  650. }
  651.  
  652.  
  653. static OSErr RendIntent2String ( unsigned long intent, StringPtr dest )
  654. {
  655.     return GetFlagListStringPtr( 1000, intent, dest ) ;
  656. }
  657.  
  658. static OSErr ColorSpace2String ( OSType spaceType, StringPtr dest )
  659. {
  660.     return GetOSTypeListStringPtr( 129, spaceType, dest ) ;
  661. }
  662.  
  663. static OSErr ProfileClass2String ( OSType classType, StringPtr dest )
  664. {
  665.     return GetOSTypeListStringPtr( 128, classType, dest ) ;
  666. }
  667.  
  668.  
  669.  
  670.  
  671.  
  672. /*------------------------------------------------------------------------------*\
  673.     DoCreateProfWindow
  674.  *------------------------------------------------------------------------------*
  675.         This routine actually creates the WindowRef for a winHandle.
  676.         After creating the window, it:
  677.             reference the window and the DocumentRecord to each other,
  678.             makes the window the current port,
  679.             resizes the window according to the WIND resource,
  680.             titles it according the the FSSpec, and
  681.             makes it visible .
  682.         This routine is called by:
  683.             winOpenProfList() which fills in the winHandle structure
  684. \*------------------------------------------------------------------------------*/
  685. static OSErr DoCreateProfWindow ( winHandle win )
  686. {
  687.     OSErr            err = noErr ;
  688.     WindowRef        window ;
  689.     FSSpec            spec ;
  690.     OSType            subtype ;
  691.     Str255            winTitle="\p" ;
  692.         
  693.     // create the window
  694.     window = GetNewCWindow(rProfileWindID, nil, (WindowRef)-1 ) ;
  695.             
  696.     SetWinWindow( win, window ) ;            // save a reference to the window in the winRecord
  697.     SetWindowWinHandle ( window, win ) ;        // save a reference to the winRecord in the window
  698.  
  699.     SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ;    // set the window to be the current port
  700.  
  701.     SetWinRect( win, ((CGrafPtr)window)->portRect ) ;
  702.  
  703.     spec = GetWinFSSpec( win ) ;
  704.     subtype = GetWinSubtype( win ) ;
  705.  
  706.     // set the name of this document window
  707.     switch (subtype)
  708.     {
  709.         case kHandleSubType :
  710.              break ;
  711.  
  712.         case kFileSubType :
  713.             SetWTitle( window, spec.name ) ;
  714.             break ;
  715.             
  716.         case kEmbededSubType :
  717.             NumToString( GetProfIDIndex(win), winTitle ) ;
  718.             pStrIns( winTitle, "\p:", 255 ) ;
  719.             pStrIns( winTitle, spec.name, 255 ) ;
  720.             SetWTitle( window, winTitle ) ;
  721.             break ;
  722.     }
  723.     
  724.     // make sure it is visible
  725.     ShowWindow( window ) ;
  726.     
  727.     return err ;
  728. }
  729.  
  730.  
  731. static void ProfIDSearchListCmnd ( winHandle win )
  732. {
  733.     OSErr                    err = noErr ;
  734.     CMProfileIdentifierHdl    profIDHdl ;
  735.     winHandle                newWin ;
  736.     
  737.     // create a a new handle copied from the win's ProfileIdentifier handle
  738.     profIDHdl = GetProfIDIDHdl( win ) ;
  739.     err = HandToHand( (Handle*)&profIDHdl );
  740.     WarnIfErr( err ) ;
  741.     if (err) return ;
  742.  
  743.     // create a new winHandle of the proper type
  744.     err = NewWinHandle( &newWin, winAllocProfList ) ;
  745.     WarnIfErr( err ) ;
  746.     if (err) return ;
  747.  
  748.     // set the subtype of the winHandle so that the correct search is done
  749.     SetWinSubtype( newWin, kProfIDListSubtype ) ;    // set subtype
  750.     SetProfListIdentHdl( newWin, profIDHdl ) ;
  751.     
  752.     err = CallWinNewProc( newWin ) ;
  753.     if ( err != noErr )
  754.         DisposeWinHandle( newWin ) ;
  755.  
  756.     if ( err == kWasAlreadyOpen )
  757.         err = noErr;
  758. }
  759.  
  760. /*------------------------------------------------------------------------------*\
  761.     SaveCmndProfile
  762.  *------------------------------------------------------------------------------*
  763. \*------------------------------------------------------------------------------*/
  764. static void SaveCmndProfID ( winHandle win ) 
  765. {
  766.     FSSpec                spec ;
  767.     Boolean                dirty ;
  768.     Boolean                hasFile ;
  769.     OSErr                err ;
  770.     OSType                subtype ;
  771.     
  772.     spec = GetWinFSSpec( win ) ;
  773.     dirty = GetWinDirty( win ) ;
  774.     hasFile = ( spec.name[0] > 0 ) ;
  775.     subtype = GetWinSubtype( win ) ;
  776.  
  777.     if ( !dirty ) return;                // no need to save
  778.     if ( subtype!=kFileSubType) return;    // can't save
  779.     
  780.     if ( !hasFile )
  781.         SaveAsCmndProfID( win ) ;
  782.     else
  783.     {
  784.         err = WriteProfileIdentifier( spec, GetProfIDIDHdl(win), kCreatorType ) ;
  785.         if (err) return ;                // if err, should do something
  786.         SetWinDirty( win, false ) ;
  787.         DoAppAdjustMenus() ;            // undim app items
  788.     }
  789. }
  790.  
  791.  
  792. /*------------------------------------------------------------------------------*\
  793.     SaveAsCmndProfID
  794.  *------------------------------------------------------------------------------*
  795. \*------------------------------------------------------------------------------*/
  796. static void SaveAsCmndProfID ( winHandle win ) 
  797. {
  798.     FSSpec                spec ;
  799.     Boolean                dirty ;
  800.     Boolean                hasFile ;
  801.     StandardFileReply    reply ;
  802.     OSErr                err ;
  803.     WindowRef            window ;
  804.     Str255                title ;
  805.     OSType                subtype ;
  806.     
  807.     spec = GetWinFSSpec( win ) ;
  808.     dirty = GetWinDirty( win ) ;
  809.     hasFile = ( spec.name[0] > 0 ) ;
  810.     subtype = GetWinSubtype( win ) ;
  811.     window = GetWinWindow( win ) ;
  812.     
  813.     if ( hasFile )
  814.         StringToString( spec.name, title ) ;
  815.     else
  816.         GetWTitle( window, title ) ;
  817.     
  818.     StandardPutFile( "\pSave ProfID as:", title, &reply) ;
  819.     if ( reply.sfGood )
  820.     {
  821.         spec = reply.sfFile ;
  822.         err = WriteProfileIdentifier( spec, GetProfIDIDHdl(win), kCreatorType ) ;
  823.         WarnIfErr( err ) ;
  824.         if ( err ) return ;                    // if err, should do something 
  825.         SetWinFSSpec( win, &spec ) ;        // win's spec = new spec
  826.         SetWTitle( window, spec.name ) ;    // win title = new title
  827.         SetWinSubtype( win, kFileSubType ) ;
  828.         SetWinDirty( win, false ) ;
  829.         DoAppAdjustMenus() ;                // undim app items
  830.     }
  831. }
  832.  
  833.  
  834. /*------------------------------------------------------------------------------*\
  835.     RevertCmndProfID
  836.  *------------------------------------------------------------------------------*
  837. \*------------------------------------------------------------------------------*/
  838. static void RevertCmndProfID ( winHandle win ) 
  839. {    
  840.     FSSpec                spec ;
  841.     Boolean                dirty ;
  842.     Boolean                hasFile ;
  843.     OSType                subtype ;
  844.  
  845.     spec = GetWinFSSpec( win ) ;
  846.     dirty = GetWinDirty( win ) ;
  847.     hasFile = ( spec.name[0] > 0 ) ;
  848.     subtype = GetWinSubtype( win ) ;
  849.     
  850.     if ( !dirty || !hasFile ) return ;
  851.     if ( subtype!=kFileSubType) return;    // can't revert
  852.         
  853.                                     // ask user if it's ok
  854.     
  855.     SetWinDirty( win, false ) ;        // clear dirty so we don't get another dialog
  856.     CallWinCloseProc( win ) ;        // close the document
  857.     SendODOC( &spec ) ;                // reopen: send ODOC event to ourselves:
  858. //    DoAppAdjustMenus() ;            // undim app items
  859. }
  860.  
  861.  
  862. #define LMGetWMgrCPort() (* (GrafPtr *) 0x0D2C)
  863.  
  864. static long PopUpMenuSelectFont (MenuHandle theMenu,
  865.                             short top, short left,
  866.                               short popUpItem,
  867.                               short font, short size)
  868. {
  869.     long    result;
  870.     short    SaveSysFontFam;
  871.     GrafPtr    wmPtr,wmCPtr;
  872.     short    SaveWPortFont;
  873.     short    SaveWPortSize;
  874.     
  875.     wmPtr  = LMGetWMgrPort();
  876.     wmCPtr = LMGetWMgrCPort();
  877.     SaveWPortFont  = wmPtr->txFont;
  878.     SaveWPortSize  = wmPtr->txSize;
  879.     
  880.     SaveSysFontFam = LMGetSysFontFam();
  881.     LMSetSysFontFam(font);
  882.     wmCPtr->txFont = font;
  883.     wmCPtr->txSize = size;
  884.     wmPtr->txFont  = font;
  885.     wmPtr->txSize  = size;
  886.     
  887.     result = PopUpMenuSelect(theMenu,top,left,popUpItem);
  888.     
  889.     LMSetSysFontFam(SaveSysFontFam);
  890.     wmCPtr->txFont = SaveWPortFont;
  891.     wmCPtr->txSize = SaveWPortSize;
  892.     wmPtr->txFont  = SaveWPortFont;
  893.     wmPtr->txSize  = SaveWPortSize;
  894.     
  895.     return result;
  896. }
  897.  
  898.  
  899. /*------------------------------------------------------------------------------*\
  900.     GetFlagListStringPtr
  901.  *------------------------------------------------------------------------------*
  902.         This routine loads a 'BTS#' resource and loops through it looking
  903.         for the string that coresponds to the type parameter.
  904. \*------------------------------------------------------------------------------*/
  905.  
  906. static OSErr GetFlagListStringPtr( short id, unsigned long flags, StringPtr dest )
  907. {
  908.     short            i, count;
  909.     short            shift ;
  910.     long            maskShift, valueShift ;
  911.     FlagListHdl        list ;
  912.     
  913.     list = (FlagListHdl) GetResource('BTS#', id) ;
  914.     if (list==nil) return ResError() ;
  915.     
  916.     count = (**list).count ;
  917.     dest[0] = 0 ;
  918.     
  919.     for (i=0; i<count; i++ )
  920.     {
  921.         shift = (**list).entry[i].shift ;
  922.         maskShift  = ((unsigned long)((**list).entry[i].mask))  << shift ;
  923.         valueShift = ((unsigned long)((**list).entry[i].value)) << shift ;
  924.  
  925.         if ( (flags & maskShift) == valueShift )
  926.         {
  927.             if (dest[0]) pStrCat( dest, "\p, ", 255 );
  928.             pStrCat( dest, (StringPtr)&((**list).entry[i].string), 255 );
  929.         }
  930.     }
  931.     ReleaseResource( (Handle)list ) ;
  932.     return noErr ;
  933. }
  934.  
  935. static OSErr BuildFlagListMenu ( short id, unsigned long flags, MenuHandle menu )
  936. {
  937.     short            j, i, count;
  938.     short            shift, lastshift ;
  939.     long            maskShift, valueShift ;
  940.     FlagListHdl        list ;
  941.     
  942.     list = (FlagListHdl) GetResource('BTS#', id) ;
  943.     if (list==nil) return ResError() ;
  944.     
  945.     count = (**list).count ;
  946.     
  947.     for (j=i=0; i<count; i++, j++ )
  948.     {
  949.         shift = (**list).entry[i].shift ;
  950.         maskShift  = ((unsigned long)((**list).entry[i].mask))  << shift ;
  951.         valueShift = ((unsigned long)((**list).entry[i].value)) << shift ;
  952.  
  953.         if ( (i!=0) && (lastshift!=shift) )
  954.         {
  955.             AppendMenu( menu, "\p-" );
  956.             j++;
  957.         }
  958.             
  959.         AppendMenu(menu, (StringPtr)&((**list).entry[i].string) );
  960.         if ( (flags & maskShift) == valueShift )
  961.             SetItemMark(menu,j+1,0xC3);
  962.         
  963.         lastshift = shift ;
  964.     }
  965.     ReleaseResource( (Handle)list ) ;
  966.     return noErr ;
  967. }
  968.  
  969. static OSErr SetFlagFromMenuItem ( short id, unsigned long *flags, short mitem )
  970. {
  971.     short            j, i, count;
  972.     short            shift, lastshift ;
  973.     long            maskShift, valueShift ;
  974.     FlagListHdl        list ;
  975.     unsigned long    flagsBefore ;
  976.     
  977.     flagsBefore = *flags ;
  978.  
  979.     list = (FlagListHdl) GetResource('BTS#', id) ;
  980.     if (list==nil) return ResError() ;
  981.     
  982.     count = (**list).count ;
  983.     
  984.     for (j=i=0; i<count; i++, j++ )
  985.     {
  986.         shift = (**list).entry[i].shift ;
  987.         maskShift  = ((unsigned long)((**list).entry[i].mask))  << shift ;
  988.         valueShift = ((unsigned long)((**list).entry[i].value)) << shift ;
  989.  
  990.         if ( (i!=0) && (lastshift!=shift) )
  991.             j++;
  992.         
  993.         if (mitem == j+1)
  994.             *flags = ((*flags) & (~maskShift)) | (valueShift);
  995.  
  996.         lastshift = shift ;
  997.     }
  998.     ReleaseResource( (Handle)list ) ;
  999.     
  1000.     return (flagsBefore == *flags) ;        // return something if there was no change
  1001. }
  1002.  
  1003.  
  1004.